/**
 * Created by yihua on 2017/3/4.
 */
$(document).ready(function () {
    $("#add_confirm").unbind('click').click(function () {
        //$("#deleteModal").modal("hide");
        var options = {
            url: '/home/management/addrecommenduser',
            beforeSubmit: validate,  // pre-submit callback
            success: showResponse,  // post-submit callback
            dataType: 'json',
            type: 'get',
        };
        $("#addForm").ajaxSubmit(options);
    });
    function validate(formData) {
        for (var i = 0; i < formData.length; i++) {
            if (!formData[i].value) {
                toastr.error('请输入所有选项', '', {positionClass: 'toast-bottom-center'});
                return false;
            }
        }
    }

    function showResponse(responseText) {

        if (0 !== responseText.errno) {
            toastr.error(responseText.errmsg, '', {positionClass: 'toast-bottom-center'});
        }
        else {
            toastr.success('增加成功', '', {positionClass: 'toast-bottom-center'});
            $('#addrecommand').modal('hide');
            window.location.reload();
        }
    }

});